<template>
  <div class="tableList" ref="tableList">
    <a-table
      :columns="tableColumns"
      :data-source="tableDataSource"
      :scroll="state.tableScroll"
      :pagination="false"
      size="small"
      bordered
      :rowClassName="setRowClassName"
    >
      <template #bodyCell="{ column, record, index }">
        <template v-if="column.key === 'action'">
          <InfoCircleFilled
            :style="{fontSize: '16px', color: 'rgb(120, 154, 255)', cursor: 'pointer'}"
            @click="handleClickRowIcon(record)"
          />
        </template>
        <!-- 序号 -->
      <template v-if="column.key === 'index'">
        <span>{{index + 1 + ((state.pagination.current - 1) * state.pagination.pageSize)}}</span>
      </template>
        <template v-if="column.dataIndex === 'wptn'">
          <span class="redText wptnSpan" v-if="record.wptn == 1"> ↑ </span>
          <span class="blueText wptnSpan" v-if="record.wptn == 0"> ㅡ </span>
          <span class="greenText wptnSpan" v-if="record.wptn == 2"> ↓ </span>
        </template>
        <template v-if="column.dataIndex === 'tm'">
          {{ record.tm && record.tm.length > 11 ? dayjs(record.tm).format('MM-DD HH:mm') : record.tm }}
        </template>
        <template v-if="column.dataIndex === 'tmMin'">
          {{ record.tmMin && record.tmMin.length > 11 ? dayjs(record.tm).format('MM-DD HH:mm') : record.tmMin }}
        </template>
      </template>
    </a-table>
  </div>
</template>

<script lang="ts" setup>
  import { ref, reactive, watch, inject } from "vue";
  import { InfoCircleFilled } from '@ant-design/icons-vue';
  import { useStationDataStoreWithOut } from '@/store/modules/stationData';
  import dayjs from 'dayjs';

  const stationDataStore = useStationDataStoreWithOut();

  defineOptions({ name: "TablePopup" });
  const tableList = ref(null);
  const state = reactive({
    pageNum: 1,
    tableScroll: { y: 475 },
    dataSource: [],
    lightIndex: -1,
    pagination: {
      current: 1,
      total: 0,
      pageSize: 30,
      showQuickJumper: true,
      showSizeChanger: true,
      showTotal: total => `共 ${total} 条`,
      onChange: pageNumber => {
        state.pagination.current = pageNumber
        state.tableData = cloneDeep(state.dataSource).splice((pageNumber - 1) * state.pagination.pageSize, state.pagination.pageSize)
      }
    },
  });

  defineProps({
    tableDataSource: { type: Object },
    tableColumns: { type: Object },
  });

  const setRowClassName = (record, index) => {
    if (index == state.lightIndex) {
      return "rowcolor";
    } else {
      return;
    }
  };

  // 点击表格当前点击的行，弹窗过程线详情
  const handleClickRowIcon = (record) => {
    stationDataStore.setStationData(record);
  };


  // 监听是否点击了全屏，重新渲染下
  const modalHeightChange = inject("ModalHeightChange");
  watch(
    () => modalHeightChange.value,
    (val) => {
      state.tableScroll.y = val - 205;
    }
  );
</script>

<style lang="less" rel="stylesheet/less" scoped>
.tableList {
  width: 100%;
  height: 100%;
  transform: translateX(0);
  transition: all 0.5s;
  position: relative;
  ::v-deep(.ant-table) {
    .ant-table-thead > tr > th {
      padding: 8px 0px !important;
    }

    .ant-table-container > .ant-table-body > table > tbody > tr > td {
      padding: 0px 6px !important;
      height: 34px;
    }
    .rowcolor {
      font-weight: 700;
    }
    p {
      margin: 0 !important;
    }
  }
  .pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 24px;
    border-top: 1px solid #f0f0f0;
    position: absolute;
    left: 0;
    bottom: 0px;
    z-index: 100;
    background: #fff;
    .iconify {
      color: #ccc;
      cursor: pointer;
    }
  }
  .isShowPagination {
    opacity: 0;
  }
}

.wptnSpan {
  &.redText {
    color: red;
  }
  &.blueText {
    color: #0070ff;
  }
  &.greenText {
    color: green;
  }
}
</style>
